
// Import any other script files here, e.g.:
// import * as myModule from "./mymodule.js";

import CAMERA_CLASS from "./cameraClass.js";
import RoleClass from "./Role.js";
import Block from "./Block.js";
import GAMEFUNC_ from "./func.js";
import MAIN_CANVAS from "./CANVAS.js";
import XNF_RuntimeLibrary from "./runtime.js";
import ON_BLOCK from "./onBlock.js";
import XNF_DATA from "./XNF_DATA.js";

runOnStartup(async runtime =>
{
	// Code to run on the loading screen.
	// Note layouts, objects etc. are not yet available.
	
	runtime.addEventListener("beforeprojectstart", () => OnBeforeProjectStart(runtime));
});

async function OnBeforeProjectStart(runtime)
{
	// Code to run just before 'On start of layout' on
	// the first layout. Loading has finished and initial
	// instances are created and available to use here.

	//XNF_DATA
	runtime.addEventListener("save",  XNF_DATA.DATA_listener.onGameSave);
	runtime.addEventListener("load",  XNF_DATA.DATA_listener.onGameLoad);
	runtime.addEventListener("keydown",e=>XNF_DATA.DATA_listener.KEY_DOWN(e,runtime))
	runtime.addEventListener("tick", e=>XNF_DATA.MAIN_EVENTHANDLER_(runtime))
	runtime.addEventListener("tick",e=>XNF_DATA.INIT_EVENTHANDLER(runtime))




	runtime.addEventListener("tick", () => Tick(runtime));
	//ROLE
	runtime.addEventListener("tick",()=>RoleClass.TICK(runtime));
	runtime.layout.addEventListener("beforelayoutstart", () => RoleClass.RUNTIME_LAYOUT_START(runtime));
	runtime.addEventListener("mousedown", e => RoleClass.RUNTIME_INPUT._INPUT_MOUSE_DOWN(e,runtime));
	//Block
	runtime.addEventListener("tick",()=>Block.TICK(runtime));
	runtime.layout.addEventListener("beforelayoutstart", () =>Block.RUNTIME_LAYOUT_START(runtime));
	//CANVAS
	runtime.layout.addEventListener("tick",()=>MAIN_CANVAS.TICK(runtime))
	runtime.layout.addEventListener("beforelayoutstart", () =>MAIN_CANVAS.MAIN_START(runtime))
	//CAMERA
	runtime.addEventListener("tick",()=>CAMERA_CLASS.TICK(runtime));
	runtime.layout.addEventListener("beforelayoutstart", () => CAMERA_CLASS.RUNTIME_LAYOUT_START(runtime))
	//runtime_
	runtime.addEventListener("tick",()=>XNF_RuntimeLibrary.TICK(runtime))
	runtime.layout.addEventListener("beforelayoutstart", () =>XNF_RuntimeLibrary.RUNTIME_LAYOUT_START(runtime))
	//on_block.js
	runtime.addEventListener("tick",()=>ON_BLOCK.EVENTHANDLER(runtime))


}


function Tick(runtime)
{

}

function save(e)
{
	console.log("hi save")
}